package com.qububu.emporium.orderform.dto;

import java.util.Arrays;

import com.qububu.utils.DateUtil;
import com.qububu.utils.SystemUtil;

public class OrderFormInfoDto {
	private String orderId; // 订单ID
	private String orderNo; // 订单号
	private int orderCreateDttm; // 订单生成时间
	private OrderPayType orderPayType; // 支付类型
	private double orderAmount; // 订单总价
	private String remark; // 备注
	private String userAddr; // 购买者地址
	private String userPhoneNumber; // 购买者电话号码
	private String userName; // 购买者名字
	private int orderReceiveDt; // 收货时间
	private OrderStatus status;

	public String getOrderId() {
		return orderId;
	}

	public String getOrderNo() {
		return orderNo;
	}

	public int getOrderCreateDttm() {
		return orderCreateDttm;
	}

	public void setOrderCreateDttm(int orderCreateDttm) {
		this.orderCreateDttm = orderCreateDttm;
	}

	public OrderPayType getOrderPayType() {
		return orderPayType;
	}

	public void setOrderPayType(OrderPayType orderPayType) {
		this.orderPayType = orderPayType;
	}

	public double getOrderAmount() {
		return orderAmount;
	}

	public void setOrderAmount(double orderAmount) {
		this.orderAmount = orderAmount;
	}

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	public String getUserAddr() {
		return userAddr;
	}

	public void setUserAddr(String userAddr) {
		this.userAddr = userAddr;
	}

	public String getUserPhoneNumber() {
		return userPhoneNumber;
	}

	public void setUserPhoneNumber(String userPhoneNumber) {
		this.userPhoneNumber = userPhoneNumber;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public int getOrderReceiveDt() {
		return orderReceiveDt;
	}

	public void setOrderReceiveDt(int orderReceiveDt) {
		this.orderReceiveDt = orderReceiveDt;
	}
	
	public OrderStatus getStatus() {
		return status;
	}

	public void setStatus(OrderStatus status) {
		this.status = status;
	}
	
	public String showOrderCreateTimeToDttm() {
		return DateUtil.formatToDTTMString(orderCreateDttm);
	}

	public String showOrderReceiveTimeToDt() {
		return DateUtil.formatDTString(orderReceiveDt);
	}
	
	/**
	 * @ 得到加密的 id
	 */
	public OrderFormInfoDto(String orderId, String orderNo){
		this.orderId = orderId;
		this.orderNo = orderNo;
	}
	
	/**
	 * @ 得到未加密的 id
	 */
	public OrderFormInfoDto(long orderId, String orderNo){
		this.orderId = SystemUtil.encrypt(String.valueOf(orderId));
		this.orderNo = orderNo;
	}
	
	/**
	 * 支付类型
	 * */
	public enum OrderPayType {
		COD(0),// 货到付款
		ONLINE_PAYMENT(1); // 在线支付
		
		private int intValue;
		
		private OrderPayType(int intValue) {
			this.intValue = intValue;
		}
		
		/**
		 * 根据传入字符串来返回对应的状态类型
		 */
		public static OrderPayType getOrderPayType(String strValue) {
			try {
				OrderPayType type = valueOf(strValue);
				return type;
			}
			catch(Exception ex) {
				throw new IllegalArgumentException("Value '" + strValue + "' is not allowed in OrderPayType. Only "
						+ Arrays.toString(OrderPayType.values()) + " are allowed."
						);
			}
		}
		
		public static OrderPayType getOrderPayType(int intValue) {
			for (OrderPayType elem : OrderPayType.values()) {
				if (elem.toIntValue() == intValue) {
					return elem;
				}
			}

			throw new IllegalArgumentException("Value '" + intValue
					+ "' is not allowed in OrderPayType.");
		}
		
		/**
		 * 返回int值类型。
		 * @return
		 */
		public int toIntValue() {
			return intValue;
		}
	}
	
	/**
	 * 订货单状态
	 * */
	public enum OrderStatus {
		undisposed(0),// 未处理的
		processed(1), // 已处理
		lossed(2);// 作废
		
		private int intValue;
		
		private OrderStatus(int intValue) {
			this.intValue = intValue;
		}
		
		/**
		 * 根据传入字符串来返回对应的状态类型
		 */
		public static OrderStatus getOrderStatus(String strValue) {
			try {
				OrderStatus type = valueOf(strValue);
				return type;
			}
			catch(Exception ex) {
				throw new IllegalArgumentException("Value '" + strValue + "' is not allowed in OrderStatus. Only "
						+ Arrays.toString(OrderPayType.values()) + " are allowed."
						);
			}
		}
		
		public static OrderStatus getOrderStatus(int intValue) {
			for (OrderStatus elem : OrderStatus.values()) {
				if (elem.toIntValue() == intValue) {
					return elem;
				}
			}

			throw new IllegalArgumentException("Value '" + intValue
					+ "' is not allowed in OrderStatus.");
		}
		
		/**
		 * 返回int值类型。
		 * @return
		 */
		public int toIntValue() {
			return intValue;
		}
	}
}
